#include "mysql_message.hpp"

void Insert(xu::ManageMessage::ptr mu)
{
    xu::Message m1("消息ID1", boost::posix_time::time_from_string("2002-01-20 23:59:59.000"),
    "用户ID1","会话ID1",  0);
    xu::Message m2("消息ID2", boost::posix_time::time_from_string("2002-01-21 23:59:59.000"),
    "用户ID2","会话ID1",  0);
    xu::Message m3("消息ID3", boost::posix_time::time_from_string("2002-01-20 23:59:59.000"),
    "用户ID3","会话ID2",  0);
    xu::Message m4("消息ID4", boost::posix_time::time_from_string("2002-01-21 23:59:59.000"),
    "用户ID3","会话ID2",  0);

    mu->Insert(m1);
    mu->Insert(m2);
    mu->Insert(m3);
    mu->Insert(m4);
}

void Delete(xu::ManageMessage::ptr mu)
{
    mu->Delete("会话ID1");
}

void SelectMessageN(xu::ManageMessage::ptr mu)
{
    auto res =  mu->SelectMessageN("会话ID2",1);
    for(auto e : res)
    {
        std::cout<<e.message_id()<<std::endl;
    }
}

void SelectMessageRange(xu::ManageMessage::ptr mu)
{
    boost::posix_time::ptime stime(boost::posix_time::time_from_string("2002-01-20 23:59:59.000"));
    boost::posix_time::ptime etime(boost::posix_time::time_from_string("2002-01-21 23:59:59.000"));
    auto res =  mu->SelectMessageRange("会话ID2",stime,etime);
    for(auto e : res)
    {
        std::cout<<e.message_id()<<std::endl;
    }
}

int main()
{
    InitLog(false);
    auto db = xu::MysqlClientFactory::Create("root","xzyxzy99","xu","127.0.0.1","utf8");
    xu::ManageMessage::ptr mu = std::make_shared<xu::ManageMessage>(db);
    //Insert(mu);
    //Delete(mu);
    //SelectMessageN(mu);
    SelectMessageRange(mu);
    return 0;
}